/*
 * @Description: call apply bind
 * @Author: wangchao
 * @Date: 2023-02-06 17:51:39
 */

Function.prototype.wcCall = function (context, ...args) {
  context.func = this
  let res = context.func(...args)
  delete context.func
  return res
}
Function.prototype.wcApply = function (context, args = []) {
  context.func = this
  let res = Array.isArray(args) ? context.func(...args) : context.func(args)
  delete context.func
  return res
}
Function.prototype.wcBind = function (context) {
  let _self = this
  return function () {
    context.func = _self
    let res = context.func(...[...arguments])
    delete context.func
    return res
  }
}

function fn(a, b) {
  console.log(a, b, this.name);
}
let obj = {
  name: 'hello1'
}

// fn.wcCall(obj, 1, 2)
// fn.wcCall(obj, [3,4])
// fn.wcApply(obj, [3, 2])
// fn.wcApply(obj)
// let bindFn = fn.wcBind(obj)
// bindFn(5,6,7)